package com.jianyun.jyzs.utils;

import android.content.Context;
import android.content.res.AssetManager;


import com.jianyun.jyzs.bean.ProvinceModel;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

/**
 * Created by mlli on 2017/8/30.
 */

public class ProvinceCXml {

    public static List<ProvinceModel> initProvice(Context context) {
        AssetManager asset = context.getAssets();
        List<ProvinceModel> dataList = new ArrayList<>();
        try {
            InputStream input = asset.open("province_data.xml");
            // 创建一个解析xml的工厂对象
            SAXParserFactory spf = SAXParserFactory.newInstance();
            // 解析xml
            SAXParser parser = spf.newSAXParser();
            XmlParserHandler handler = new XmlParserHandler();
            parser.parse(input, handler);
            input.close();
            // 获取解析出来的数据
            dataList = handler.getDataList();
            return dataList;
        } catch (Exception e) {
            e.printStackTrace();
            return dataList;
        }
    }
}
